<% availableModels = available_models %>
<% availableServices = available_services %>
<% availableResources = available_resource_types %>

<nav class="navbar navbar-default navbar-fixed-top" id="top" role="navigation">
  <div class="container-fluid">
 <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <a type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav-collapse-in">
        <i class="fa fa-angle-down"></i>
      </a>
      <!--logo-->
      <div class="logo-header">
        <%= link_to(image_tag('logo/brand.svg', :alt => t('site.name')), '/', :class => "logo"); %>
      </div>
      <!--BROWSE-->
      <%= render partial: 'layouts/header/browse_header'%>

    </div>

    <!--collapse-->
    <div class="collapse navbar-collapse" id="nav-collapse-in">

      <ul class="nav nav-pills desktop-nav pull-right hidden-xs">

        <!--navegation-->
        <%= render partial: 'layouts/header/basic_navegation' %>

        <!--add-->
        <li class ="btn-group">
          <a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
            <i class="fa fa-plus"></i>
          </a>
          <ul class="dropdown-menu dropdown-menu-right">
            <% availableModels.each do |modelName| %>
                <% if modelName == "Excursion" %>
                  <li><%= link_to new_excursion_path do %><i class="fa fa-list-alt"></i> <%= t('excursion.actions.add') %><% end %></li>
                <% elsif modelName == "Workshop" %>
                  <li><%= link_to new_workshop_path do %><i class="fa fa-book"></i> <%= t('workshop.actions.add') %><% end %></li>
                <% elsif modelName == "Resource" %>
                  <li><a href="#AddResource" data-toggle="modal"><i class="fa fa-file"></i> <%=t('resource.actions.add')%></a></li>
                  <% if availableResources.include? "Writing" %>
                    <li><%= link_to new_writing_path do %><i class="fa fa-edit"></i> <%= t('writing.actions.add') %><% end %></li>
                  <% end %>
                <% elsif modelName == "Category" %>
                  <li><a href="#AddCategoryHeader" data-toggle="modal"><i class="fa fa-th-large"></i> <%=t('categories.actions.add')%></a></li>
                <% elsif modelName == "Event" %>
                  <li><a href="#AddEvent" data-toggle="modal"><i class="fa fa-video-camera"></i> <%=t('event.actions.add')%></a></li>
                <% elsif modelName == "Course" %>
                  <%if Vish::Application.config.courses_enabled && current_subject.admin?%>
                    <li><%= link_to new_course_path do %><i class="fa fa-graduation-cap"></i> <%=t('course.actions.add')%><% end %></li>
                  <%end%>
                <%end%>
            <% end %>
          </ul>
        </li>


          <!--user-->
          <li class ="btn-group user-menu">
                <%= link_to current_subject, {:class => "btn btn-default photo-user tooltip-header", :data => {:toggle=>"tooltip"}, :'data-original-title'=>t('profile.profile')} do %>
                  <%= image_tag current_subject.logo.url(:small) %>
                <% end %>

                <a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                    <span class="user_text"><%= truncate_name(current_subject.name, length: 12) %></span>
                    <i class="fa fa-angle-down"></i>
                </a>

                <ul class="dropdown-menu dropdown-menu-right">
                   <li class="settings-menu">
                     <%= link_to home_path do %>
                     <i class="fa fa-home"></i>
                     <%= t('navigation.home') %>
                     <% end %>
                   </li>

                   <li class="settings-menu">
                    <%= link_to current_subject do %>
                    <i class="fa fa-user"></i>
                    <%= t('profile.one') %>
                    <% end %>
                  </li>

                  <%if isAdmin? %>
                     <li class="settings-menu">
                       <%= link_to admin_path do %>
                         <i class="fa fa-wrench"></i>
                         <span><%= 'Admin Panel' %></span>
                       <% end %>
                     </li>
                   <%end%>

                  <% if availableModels.include? "Excursion" and availableServices.include? "ARS" and !current_subject.role?("PrivateStudent") %>
                      <!-- divider bar -->
                      <li class="divider"></li>

                      <li class="settings-menu">
                        <%= link_to quiz_sessions_path do %>
                          <i class="fa fa-check-square-o"></i>
                          <%= t('quiz.live') %>
                        <% end %>
                      </li>
                  <%end%>

                  <%if (availableModels.include? "Course") && current_subject.courses.length>0 %>
                    <li class="settings-menu">
                      <%= link_to "/users/"+current_subject.slug+"/courses" do %>
                          <i class="fa fa-graduation-cap"></i>
                          <span><%= t('course.my') %></span>
                      <% end %>
                    </li>
                  <%end%>

                  <% if availableServices.include? "PrivateStudentGroups" and !current_subject.role?("PrivateStudent") %>
                      <li class="settings-menu">

                        <% if can?(:create, PrivateStudentGroup.new) %>
                          <%= link_to private_student_groups_path do %>
                            <i class="fa fa-university"></i>
                            <%= t("private_student.request") %>
                          <% end %>
                        <% else %>
                          <%= link_to(raw("<i class='fa fa-group'></i> " + t("private_student.request")), new_service_request_private_student_group_path, :title => t("private_student.request_help"), :remote=>true, :data => {:toggle=>"modal", :target=>"#RequestPermModal"}) %>
                        <% end %>

                      </li>
                  <%end%>

                  <!-- divider bar -->
                  <li class="divider"></li>

                  <% unless current_subject.role?("PrivateStudent") %>
                    <li class="settings-menu">
                      <%= link_to settings_path do %>
                      <i class="fa fa-cog"></i>
                      <%= t('dropdown.settings') %>
                      <% end %>
                    </li>
                  <% end %>

                  <li>
                    <%= link_to destroy_user_session_path, :method => :delete do %>
                    <i class="fa fa-sign-out"></i>
                    <%= t('sign_out') %>
                    <% end %>
                  </li>

                </ul>
          </li>

      </ul>

      <!--search-->
      <%= render partial: 'layouts/header/uisearch_header' %>

      <!--________________________mobile/tablet-->
      <%= render partial: 'layouts/header/header_signed_in_mobile' %>



    </div>
  </div>

</nav>

<% if (availableServices.include? "PrivateStudentGroups") && !can?(:create, PrivateStudentGroup.new) %>
  <%= render partial: 'service_request/private_student_groups/new_modal'%>
<%end%>

 <script>
   document.addEventListener('DOMContentLoaded', function() {
      $('.tooltip-header').tooltip({ placement: 'bottom', container: 'body'});
      $('.dropdown-toggle').dropdown();

      (function ($, window, delay) {
        var theTimer = 0;
        var theElement = null;
        var theLastPosition = {x:0,y:0};
        $('.toggler .without-data-toggle')
        .closest('li')
        .on('mouseenter', function (inEvent) {
          if (theElement) theElement.removeClass('open');
          window.clearTimeout(theTimer);
          theElement = $(this);

          theTimer = window.setTimeout(function () {
            theElement.addClass('open');
          }, delay);
        })
        .on('mousemove', function (inEvent) {
          if(Math.abs(theLastPosition.x - inEvent.ScreenX) > 4 ||
           Math.abs(theLastPosition.y - inEvent.ScreenY) > 4)
          {
            theLastPosition.x = inEvent.ScreenX;
            theLastPosition.y = inEvent.ScreenY;
            return;
          }

          if (theElement.hasClass('open')) return;
          window.clearTimeout(theTimer);
          theTimer = window.setTimeout(function () {
            theElement.addClass('open');
          }, delay);
        })
        .on('mouseleave', function (inEvent) {
          window.clearTimeout(theTimer);
          theElement = $(this);
          theTimer = window.setTimeout(function () {
            theElement.removeClass('open');
          }, delay);
        });
    })(jQuery, window, 0); // 200 is the delay in milliseconds
  });
</script>
<!-- carga de modales -->
